package main

import (
	"fmt"
	"strings"
	"time"

	_ "github.com/go-sql-driver/mysql"
	"github.com/gogf/gf/util/guid"
	"github.com/jinzhu/gorm"
)

type BusinessProjects struct {
	Id         int64     `json:"id"`
	BusinessId int64     `json:"business_id"` // 业务方ID
	ProjectId  int64     `json:"project_id"`  // 项目ID
	SubCount   int       `json:"sub_count"`   // 订阅数
	Topic      string    `json:"topic"`       // kafka topic
	Extras     string    `json:"extras"`      // 订阅的额外信息
	CreatedAt  time.Time `json:"created_at"`
	UpdatedAt  time.Time `json:"updated_at"`
	IsDeleted  int       `json:"is_deleted"`
}

func main() {
	db, err := gorm.Open("mysql", "sh_crawl:QBaX3kTDoWtok2kO@tcp(10.180.18.31:4000)/kunlun?charset=utf8&parseTime=True&loc=Local")
	if err != nil {
		panic(err)
	}
	defer db.Close()

	values := ""
	count := 1000
	for i := 0; i < count; i++ {
		values += fmt.Sprintf("('%d','%d','%s','%s'),", i, i, guid.S(), "a")
		if (i+1)%100 == 0 || i == count-1 {
			values = strings.TrimRight(values, ",")
			sql := "insert into business_projects (business_id,project_id,topic,extras) values" + values
			fmt.Println(sql)
			db.Table("business_projects").Exec(sql)

			values = ""
		}
	}
}
